# -*- encoding: utf-8 -*-  
  
import urllib2  
from weixin.api.common import getAccToken
  
  
def crtMenu():
    access_token=getAccToken()
    print access_token
    posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token  
    print posturl
    menu = '''{
         "button":[
             {    
                  "type":"view",
                  "name":"中通优选",
                  "url":"http://shop-glpd.share.mai2.cn/d/V_GLPD/"
                },
            {    "name":"中通服务",
            "sub_button":[
            {
                "type":"view",
                "name":"快件查询",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0628942a43830f81&redirect_uri=http%3a%2f%2fnanjing.wuxizto.com%2fquery&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            },
            {    
                    "type":"view",
                    "name":"在线下单",
                    "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0628942a43830f81&redirect_uri=http%3a%2f%2fnanjing.wuxizto.com%2forder%2f&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            },
            {    
                    "type":"view",
                    "name":"费用明细",
                    "url":"http://nanjing.wuxizto.com/feelist/"
            },
                 {
                    "type":"click",
                    "name":"联系客服",
                    "key": "V1001_suggest"
                },
                 {
                   "type": "view",
                   "name": "投诉建议",
                   "url": "http://nanjing.wuxizto.com/suggest/"
               }]
            },
            {    "name":"了解中通",
            "sub_button":[
            {
                "type":"view",
                "name":"中通新闻",
                "url":"http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNTcwODQzMA==&hid=2&sn=7ba5089dd530ec41de3f690922420074#wechat_redirect"
            },
            {
                "type":"view",
                "name":"门店列表",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0628942a43830f81&redirect_uri=http%3a%2f%2fnanjing.wuxizto.com%2fcitylist%2f&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            },
            {
                    "name": "附近门店",
                    "type": "location_select",
                    "key": "rselfmenu_2_0",
            }]
            }
            ]
     }'''
    req=urllib2.urlopen(posturl, menu.encode('utf-8'))
    print req.read()  
crtMenu()
